package nz.ac.massey.groupproject.ecs2;

public strictfp class SpawnerSystem implements ECSSystem {

	public void tick(ECSWorld world, SpawnerComponent spa, Position pos) {
		spa.cooldown = Math.max(0, spa.cooldown - 1);
		if (spa.cooldown <= 0) {
			spa.cooldown = 30;

			double angle = 45 * StrictMath.PI / 180.0;
			int vx = (int) StrictMath.round(spa.thing_speed *  StrictMath.cos(angle));
			int vy = (int) StrictMath.round(spa.thing_speed *  StrictMath.sin(angle));
			var t = EntFactory.linearBbThingie(pos.x, pos.y, vx, vy);
			t.set(new Lifespan(60*60*10)); // 10 minutes
			world.addLater(t);

		}
	}
}
